<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ page import="com.appspot.bibtable.UrlCollection" %>
<%@ page import="com.appspot.bibtable.model.*" %>
<%@ page import="com.appspot.bibtable.view.html.*" %>
<%@ page import="com.google.appengine.api.users.*" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%
UserInfo userInfo = UserInfo.getUserInfoOf(UserServiceFactory.getUserService().getCurrentUser());
if (userInfo != null)
{
	HtmlTemplate template = new HtmlTemplate();
	template.setTitle("Profile");
	template.setRequest(request);
	template.startDocument(out);
	template.startContent(out);
	template.printSearchBox(out);
%>

<table class="stripe">
	<tr>
		<th>Bookmarks</th>
		<td><a href="/search?query=bookmark:true"><%= userInfo.countBookmark() %></a></td>
	</tr>
	<tr>
		<th>The number of items displayed on one page</th>
		<td><%= userInfo.getDisplayCount() %></td>
	</tr>
	<tr>
		<th>Adding new item</th>
		<td>
			<ul id="new-item-list">
				<li><a href="/new/book">New book</a></li>
				<li><a href="/new/article">New article</a></li>
			</ul>
		</td>
	</tr>
	<tr>
		<th>Cancel membership</th>
		<td>
			<form action="/cancel" method="post">
				<div>
					Check the checkbox to enable the button (JavaScript required).<br />
					<input type="hidden" name="key" value="<%= userInfo.getKey().hashCode() %>" />
					<input type="checkbox" id="confirm" onclick="document.getElementById('unregister').disabled = (this.checked ? null : 'disabled');" />
					<input type="submit" id="unregister" value="Unregister" disabled="disabled" onclick="return confirm('Are you sure?')" />
				</div>
			</form>
		</td>
	</tr>
</table>
<%
	template.endContent(out);
	template.endDocument(out);
}
else
{
	response.sendRedirect(UrlCollection.INDEX);
}
%>
